package com.example.demo.controller;

import com.example.demo.common.AppResult;
import com.example.demo.model.Board;
import com.example.demo.services.IBoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author baekhyun
 **/
@Api(tags = "版块接口")
@Slf4j
@RestController
@RequestMapping("/board")
public class BoardController {

    @Resource
    private IBoardService boardService;

    // 从配置文件中获取主页中显示的版块个数，默认为9
    @Value("${forum-system.index.board-num:9}")
    private Integer indexBoardNum;

    @ApiOperation("获取首页中的版块列表")
    @GetMapping("/topList")
    public AppResult<List<Board>> topList(){
        //直接调用service
        List<Board> boards=boardService.selectByNum(indexBoardNum);
        //返回结果
        return AppResult.success(boards);
    }

    /**
     * 获取指定版块信息详情
     * @param id
     * @return
     */
    @ApiOperation("获取指定版块信息详情")
    @GetMapping("/getById")
    public AppResult<Board> getBoardInfo(@ApiParam("版块Id") @RequestParam("id") @NonNull Long id){
        //调用Service
        Board board=boardService.selectById(id);
        //返回结果
        return AppResult.success(board);
    }
}
